<template>
	<view class="content">
		<u-navbar title="修改会员" height="88rpx" :placeholder='true' titleStyle='color:#fff;font-size:32rpx'
			left-icon-size="32rpx" left-icon-color="#fff" :titleStyle='titleStyle' bg-color="#FF594D" :autoBack="true">
		</u-navbar>

		<view class="change_list">
			<view class="info_item">
				<view class="left">
					姓名：
				</view>
				<view class="right">
					<input type="text" placeholder="请输入姓名" v-model="member.name" placeholder-class="placeholder" />
				</view>
			</view>
			<view class="info_item">
				<view class="left">
					手机号码：
				</view>
				<view class="right">
					<input type="number" placeholder="请输入手机号" v-model="member.phone" placeholder-class="placeholder" />
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="left" @click="submit">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	import {
		memberInfo,
		updateMember
	} from '../../../api/employee.js'
	export default {
		onLoad(option) {
			if (option.id) {
				this.id = option.id
				this.getInfo(option.id)
			}
		},
		data() {
			return {
				titleStyle: {
					color: '#fff'
				},
				member: {
					name: '',
					phone: ''
				},
				id: ''
			}
		},
		methods: {
			submit() {
				this.editMember({
					name: this.member.name,
					phone: this.member.phone,
					id: this.id,
					customerUid: this.member.memberybDTO.customerInfo.customerUid,
					memberybDTO: {
						customerInfo: {
							name: this.member.name,
							phone: this.member.phone,
						}
					}
				})
			},
			async editMember(data) {
				const res = await updateMember(data)
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: res.msg ?? '失败',
						icon: 'none'
					})
					return
				}
				uni.showToast({
					title: res.msg,
					icon: 'none'
				})
			},
			async getInfo(id) {
				const res = await memberInfo(id)
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					return
				}
				this.member = res.data
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #f3f3f3;
		min-height: 100vh;

		.change_list {
			padding: 20rpx;

			.info_item {
				border-radius: 10rpx;
				background-color: #fff;
				padding: 16rpx 30rpx;
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;

				.left {
					font-size: 26rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #333332;
					width: 160rpx;
				}

				.right {
					input {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						color: #333332;
					}

					.placeholder {
						color: #777;
					}
				}
			}
		}

		.bottom {
			width: 752rpx;
			height: 120rpx;
			background-color: #FFFFFF;
			position: fixed;
			left: 0;
			bottom: 0;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left,
			.right {
				flex: 1;
				height: 120rpx;
				background: #FF594D;
				text-align: center;
				line-height: 120rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 800;
				color: #FFFFFF;
			}

			.left {}

			.right {}
		}

	}
</style>